
    GEst = function(x.delta, x.pi, z,d,y, weights){
        # x.delta = x.pi = x
        
        pi.x.est  = predict(glm(z ~ x.pi - 1, family=binomial(link=logit), 
                                weights = weights), 
                            type = "response")
        
        g.objective = function(alpha){
            obj = t(x.delta * weights) %*% ( (y - d*tanh(x.delta %*% alpha)) * 
                                                 (z-pi.x.est) )
            return(sum(obj^2))
        }
        
        startpars = rep(0,ncol(x.delta))
        opt = Optimize(g.objective, startpars)
        alpha.est = opt$par
        
        Delta.est = sum(weights * tanh(x.delta %*% alpha.est)) / sum(weights)
        
        return(list(Delta.est=Delta.est, alpha.est = alpha.est))
        
    }